﻿using System;

namespace NetTopologySuite.Index.Bintree
{
	[Serializable]
	public class Interval
	{
		public double Min
		{
			get
			{
				return this._min;
			}
			set
			{
				this._min = value;
			}
		}

		public double Max
		{
			get
			{
				return this._max;
			}
			set
			{
				this._max = value;
			}
		}

		public double Width
		{
			get
			{
				return this.Max - this.Min;
			}
		}

		public double Centre
		{
			get
			{
				return this.Max - this.Min;
			}
		}

		public Interval()
		{
			this._min = 0.0;
			this._max = 0.0;
		}

		public Interval(double min, double max)
		{
			this.Init(min, max);
		}

		public Interval(Interval interval)
		{
			this.Init(interval.Min, interval.Max);
		}

		public void Init(double min, double max)
		{
			this.Min = min;
			this.Max = max;
			if (min > max)
			{
				this.Min = max;
				this.Max = min;
			}
		}

		public void ExpandToInclude(Interval interval)
		{
			if (interval.Max > this.Max)
			{
				this.Max = interval.Max;
			}
			if (interval.Min < this.Min)
			{
				this.Min = interval.Min;
			}
		}

		public bool Overlaps(Interval interval)
		{
			return this.Overlaps(interval.Min, interval.Max);
		}

		public bool Overlaps(double min, double max)
		{
			return this.Min <= max && this.Max >= min;
		}

		public bool Contains(Interval interval)
		{
			return this.Contains(interval.Min, interval.Max);
		}

		public bool Contains(double min, double max)
		{
			return min >= this.Min && max <= this.Max;
		}

		public bool Contains(double p)
		{
			return p >= this.Min && p <= this.Max;
		}

		private double _min;

		private double _max;
	}
}
